package com.liu.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liu.dao.ServeMedicalDao;
import com.liu.entity.ServeMedical;
import com.liu.service.intf.ServerMedicalService;
import com.liu.vo.PageBeanJson;
import com.liu.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServerMedicalServiceImpl implements ServerMedicalService {
    @Autowired
    private ServeMedicalDao serveMedicalDao;

    @Override
    public PageBeanJson<ServeMedical> list(int page, int pageSize) {
        List<ServeMedical> serveMedicalList = serveMedicalDao.select();
        PageHelper.startPage(page, pageSize);
        PageInfo<ServeMedical> pageInfo = new PageInfo<>(serveMedicalList);
        return new PageBeanJson<>(0, "ok", pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public PageBeanJson<ServeMedical> search(ServeMedical serveMedical, int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<ServeMedical> search = serveMedicalDao.search(serveMedical);
        PageInfo<ServeMedical> pageInfo = new PageInfo<>(search);
        return new PageBeanJson<>(0, "ok", pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public R insert(ServeMedical serveMedical) {
        int insert = serveMedicalDao.insert(serveMedical);
        return new R(insert, insert == 1 ? "ok" : "false", null);
    }

    @Override
    public R update(ServeMedical serveMedical) {
        int update = serveMedicalDao.update(serveMedical);
        return new R(update, update == 1 ? "ok" : "false", null);
    }

    @Override
    public R delete(int id) {
        int delete = serveMedicalDao.delete(id);
        return new R(delete, delete == 1 ? "ok" : "false", null);
    }

    @Override
    public R deleteBatch(int[] ids) {
        int i = serveMedicalDao.delBatch(ids);
        return new R(i, i >= 1 ? "ok" : "false", null);
    }
}
